﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.ExtendedReflection.Utilities.Safe.Diagnostics;

namespace PexMeHelper
{
    /// <summary>
    /// Cleans or fixes the database files of PexMe
    /// </summary>
    class Program
    {
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine("Usage: PexMeHelper <Mode>");
                Console.WriteLine(@"\t Clean: cleanes the database, \n
                                    \t Prepare: Generates commands for running all PUTs, \n
                                    \t Consolidate: Generates a consolidated test file for all tests (used while generating coverage reports) \n
                                    \t Analyze: Analyzes a given class and prints all its fields and methods");
                return;
            }

            if (args[0] == "Clean")
            {
                Console.WriteLine("Starting cleaning PexMe database");
                new PexMeDynamicDatabaseCleaner().CleanAllDynamicDB();
                Console.WriteLine("Finished cleaning PexMe database");
            }
            else if (args[0] == "Prepare")
            {
                if (args.Length != 2)
                {
                    Console.WriteLine("Usage: PexMeHelper Prepare AssemblyName");
                    return;
                }

                PUTCommandGenerator.GeneratePUTCommands(args[1]);
            }
            else if (args[0] == "Consolidate")
            {
                if (args.Length != 2)
                {
                    Console.WriteLine("Usage: PexMeHelper Consolidate DirectoryName");
                    return;
                }

                PexTestsFormatter.TestFormatter.Format(new string[] { args[1] });
            }
            else if (args[0] == "Analyze")
            {
                if (args.Length != 3)
                {
                    Console.WriteLine("Usage: PexMeHelper Consolidate AssemblyName ClassName");
                    return;
                }

                ClassAnalyzer.AnalyzeClass(args[1], args[2]);
            }
            else
            {
                Console.WriteLine("Unknown option of PexMeHelper");
            }
        }
    }
}
